package com.esd.db.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.esd.db.dao.AlipayInfoMapper;
import com.esd.db.model.AlipayInfo;
import com.esd.db.service.AlipayInfoService;

@Service("AlipayInfoService")
public class AlipayInfoServiceImpl implements AlipayInfoService {
	@Autowired
	private AlipayInfoMapper alipayInfoMapper;

	@Override
	public List<AlipayInfo> queryAlipayInfoListByWorkerIdandPayDate(int workerId, String beginDate, String endDate, int dateType, int page, int row) {
		Map<String,Object> map = new HashMap<String, Object>();
		if (page == 0) {
			map.put("begin", null);
			map.put("end", null);
		} else {
			map.put("begin", ((page - 1) * row));
			map.put("end", row);
		}
		map.put("workerId", workerId);
		map.put("beginDate", beginDate);
		map.put("endDate", endDate);
		map.put("dateType", dateType);
		return alipayInfoMapper.queryAlipayInfoListByWorkerIdandPayDate(map);
	}

	@Override
	public int queryAlipayInfoTotleByWorkerIdandPayDate(int workerId,String beginDate, String endDate, int dateType) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("workerId", workerId);
		map.put("beginDate", beginDate);
		map.put("endDate", endDate);
		map.put("dateType", dateType);
		return alipayInfoMapper.queryAlipayInfoTotleByWorkerIdandPayDate(map);
	}

	@Override
	public double queryTotleSalaryByWorkerIdandPayDate(int workerId, String beginDate, String endDate, int dateType) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("workerId", workerId);
		map.put("beginDate", beginDate);
		map.put("endDate", endDate);
		map.put("dateType", dateType);
		return alipayInfoMapper.queryTotleSalaryByWorkerIdandPayDate(map);
	}
	
	@Override
	public List<AlipayInfo> queryAlipayInfoList(String alipayAccount, String payeeRealName, String beginDate, String endDate, int dateType, int status, int page, int row, int workerId) {
		Map<String,Object> map = new HashMap<String, Object>();
		if (page == 0) {
			map.put("begin", null);
			map.put("end", null);
		} else {
			map.put("begin", ((page - 1) * row));
			map.put("end", row);
		}
		map.put("beginDate", beginDate);
		map.put("endDate", endDate);
		map.put("dateType", dateType);
		if(alipayAccount!=null){
			map.put("alipayAccount", alipayAccount);
		}else{
			map.put("alipayAccount", null);
		}
		if(payeeRealName!=null){
			map.put("payeeRealName", "%"+payeeRealName+"%");
		}else{
			map.put("payeeRealName", null);
		}
		if(status!=9){
			map.put("status", status);
		}else{
			map.put("status", null);
		}
		if(workerId != 0){
			map.put("workerId", workerId);
		}else{
			map.put("workerId", null);
		}
		return alipayInfoMapper.queryAlipayInfoList(map);
	}
	
	@Override
	public int queryAlipayInfoTotle(String alipayAccount, String payeeRealName, String beginDate,
			String endDate, int dateType, int status, int page, int row, int workerId) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("beginDate", beginDate);
		map.put("endDate", endDate);
		map.put("dateType", dateType);
		if(alipayAccount!=null){
			map.put("alipayAccount", alipayAccount);
		}else{
			map.put("alipayAccount", null);
		}
		if(payeeRealName!=null){
			map.put("payeeRealName", "%"+payeeRealName+"%");
		}else{
			map.put("payeeRealName", null);
		}
		if(status!=9){
			map.put("status", status);
		}else{
			map.put("status", null);
		}
		if(workerId != 0){
			map.put("workerId", workerId);
		}else{
			map.put("workerId", null);
		}
		return alipayInfoMapper.queryAlipayInfoTotle(map);
	}
	
	@Override
	public double queryTotleSalary(String alipayAccount, String payeeRealName, String beginDate, String endDate,
			int dateType, int page, int row, int workerId) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("beginDate", beginDate);
		map.put("endDate", endDate);
		map.put("dateType", dateType);
		if(alipayAccount!=null){
			map.put("alipayAccount", alipayAccount);
		}else{
			map.put("alipayAccount", null);
		}
		if(payeeRealName!=null){
			map.put("payeeRealName", "%"+payeeRealName+"%");
		}else{
			map.put("payeeRealName", null);
		}
		if(workerId != 0){
			map.put("workerId", workerId);
		}else{
			map.put("workerId", null);
		}
		return alipayInfoMapper.queryAlipayTotleSalary(map);
	}
}
